#include "stdafx.h"

#include "Pattern\Subject.h"

Subject::Subject()
{}


Subject::~Subject()
{}


void Subject::Notify(UINT msg, WPARAM wParam, LPARAM lParam)
{
	list<Observer*>::iterator iter  = mObserveres.begin();
	if (msg == 1)
	{
		Print("RECORD_OPT_ADD");
	}
	else if(msg==3)
	{
		Print("mOnserveres num %d", mObserveres.size());
	}
	else {
		Print("RECORD_OPT_DEL");
	}

	for (; iter != mObserveres.end(); iter++) {
		if(*iter)
			(*iter)->Update(msg, wParam, lParam);
	}
}

void Subject::Attach(Observer* pObserver)
{
	this->mObserveres.push_back(pObserver);
}



void Subject::Detach(Observer* pObserver)
{
	list<Observer*>::iterator iter;

	iter = find(mObserveres.begin(), mObserveres.end(), pObserver);

	if (iter != mObserveres.end()) {
		mObserveres.erase(iter);
	}
}





